﻿package  com.devilcat.ws{
	import com.devilcat.ws.Basicws;
	import com.worlize.websocket.*;
	import com.devilcat.dt.Pokemondt;
	import com.devilcat.dt.Itemdt;
	import com.devilcat.dt.Gamedt;
	
	public class UpdateItemws extends Basicws{
		public function UpdateItemws() {
			super("iw-protocol");
		}
		public function Update(item:Itemdt,insert:Boolean=false){
			
			var pack:Object = new Object();
			pack.iid=item.iid;
			pack.uid=Gamedt.Player.uid;
			pack.NumberOf=item.NumberOf;
			pack.Code=item.Code;
			if(insert)
				pack.action="inseritem";
			else
				pack.action="updateitem";
			var myJson:String = JSONString(pack);
			websocket.sendUTF(myJson);
			//var lupl:UserItemws = new UserItemws(Gamedt.Player.uid);
			
		}
		override function handleWebSocketOpen(event:WebSocketEvent):void
		{
		}
		override function handleWebSocketMessage(event:WebSocketEvent):void
		{
			if (event.message.type === WebSocketMessage.TYPE_UTF8)
			{	
				//tes =	JSONObject(event.message.utf8Data);
				trace("Got message: " + event.message.utf8Data);
			}
		}

	}
	
}
